﻿<?php
require_once( ROOT_DATA_ACCESS_OBJECT . 'DataAccessObject.class.php');
require_once( ROOT_DATA_OBJECT . 'DataObject.class.php');

class PessoaBO extends DataAccessObject {
	
	function inserir( $instanceDB, $dataObject ){
		$codigo = ($this->getMax( $instanceDB, $dataObject->table, "codigo" )+1);
		$dataObject->set("codigo", $codigo);
		
		$dataAtual = date('d-m-Y');

		$dataObject->set("dataCadastro", $dataAtual);
		$resultado = $this->insert( $instanceDB, $dataObject );
		
		if ( $resultado ){
			return $this->capturar( $instanceDB, $dataObject );
		}
		return FALSE;
	}
	
	function verificaExistencia($instanceDB, $rg, $cpf){
		
		if($rg == "" && $cpf == ""){
			return true;
		}else{
			
			$sqlQuery = "SELECT ";
			$sqlQuery .= "* ";
			$sqlQuery .= "FROM ";
			$sqlQuery .= "Pessoa ";
			$sqlQuery .= "WHERE ";
			$sqlQuery .= "rg = '".$rg."' OR ";
			$sqlQuery .= "cpf = '".$cpf."'";
			
			$listRetorno = $this->execute( $instanceDB, $sqlQuery, "SELECT" );
			
			if(count($listRetorno) > 0){
				return false;
			}else{
				return true;
			}
		}
	}
	
	function capturar ( $instanceDB, $dataObject ){
		return $resultado = $this->get( $instanceDB, $dataObject );
	}
	
	function alterar( $instanceDB, $dataObject ){
		return $resultado = $this->update( $instanceDB, $dataObject );
	}
	
	function excluir( $instanceDB, $dataObject ){
		return $this->delete( $instanceDB, $dataObject );
	}
}
?>
